import { HOME_CITY_LOCAT, HOME_CITY_HOT, HOME_CITY_GROUP,DELIVERLY_CITY_ID,HOME_NEAR_SHOP } from '../../actionType/homeType.jsx'
import { getHotCity, getLocatCity, getGroupCity,deliverCity,getNearShop } from '../../../http/api'
//当前定位
export const getCityLocat = (params) => {
    return async (dispatch) => {
        let res_locat = await getLocatCity()
        // let locatArr=[]
        //     locatArr.push(res_locat)
      
        dispatch({
            type: HOME_CITY_LOCAT,
            payload: {
               locatcity: res_locat
            }
        })
    }
}

//热门城市
export const getCityHot = (params) => {
    return async (dispatch) => {
        let res_hot = await getHotCity()
        
        dispatch({
            type: HOME_CITY_HOT,
            payload: {
               hotcity: res_hot
            }

        })
    }
}



//所有城市
export const getCityGroup = (params) => {
    return async (dispatch) => {
        let res_group = await getGroupCity()
        
        let groupArr=[]
        for (let i in  res_group){
            groupArr.push(res_group[i])
        }
        dispatch({
            type: HOME_CITY_GROUP,
            payload: {
                groupcity: groupArr
            }

        })
    }
}   

//传入城市ID或去城市
export const cityIdDeliver = (cityId) => {
    return async (dispatch) => {
        let city_id = await deliverCity(cityId)
        
        dispatch({
            type: DELIVERLY_CITY_ID,
            payload: {
               idcity: city_id
            }

        })
    }
    }

//派发

//获取附近商家
export const searchNearShop = (latitude,longitude) => {
    return async (dispatch) => {
        let near_shop = await getNearShop(latitude,longitude)
        
        dispatch({
            type: HOME_NEAR_SHOP,
            payload: {
               nearshop: near_shop
            }

        })
    }
    }